﻿@model Coslen.TahorCRM.Domain.Entities.ViewModels.Editing.ContactRelationshipEditViewModel
@Html.HiddenFor(model => model.ContactRelationship.ContactRelationId)
@Html.HiddenFor(model => model.ContactRelationship.CreatedAt)
@Html.HiddenFor(model => model.ContactRelationship.UpdatedAt)
@Html.HiddenFor(model => model.ContactRelationship.DeletedAt)
@Html.HiddenFor(model => model.ContactRelationship.PrimaryContactId)

<script type="text/javascript">
    $(function () {
        $('#divContactSelect').dialog({
            autoOpen: false,
            width: 400,
            resizable: false,
            title: 'Please select a contact',
            modal: true,
            open: function(event, ui) {
                //Load the CreateAlbumPartial action which will return 
                // the partial view _CreateAlbumPartial
                $(this).load("@Url.Action("GetContactSelector","Contact")");
            },
            buttons: {
                "Submit": function() {  
//                    alert("Selecting Contact....");
                    var firstName = "";
                    var lastName = "";
                    var title = "";
                    var contactID = "";
                    
                    $('#searchResults input:checked').each(function() {
                        firstName = $(this).siblings("#item_Data_FirstName").first().val();
                        lastName = $(this).siblings("#item_Data_LastName").first().val();
                        title = $(this).siblings("#item_Data_Title_Name").first().val();
                        contactID = $(this).siblings("#item_Data_ContactId").first().val();
                    });

//                    alert("firstname = [" + firstName + "]");
                    $("#secondaryContactDetails").html(lastName + ", " + title + " " + firstName);
                    $("#ContactRelationship_SecondaryContactId").val(contactID);
                    $(this).dialog("close");
                },   
                "Close": function () {
                    $(this).dialog("close");
                }
            }
        });

        $('#showContactSelect').click(function () {
            $('#divContactSelect').dialog('open');
        });
    });
</script>

<div class="editor-row">
        <div class="editor-label">
            @Html.LabelFor(model => model.ContactRelationship.PrimaryContactId)
        </div>
    <div class="editor-field">
        @Html.HiddenFor(model => model.ContactRelationship.PrimaryContactId)
        @Html.DisplayFor(model => model.ContactRelationship.PrimaryContact.LastName), @Html.DisplayFor(model => model.ContactRelationship.PrimaryContact.Title.Name) @Html.DisplayFor(model => model.ContactRelationship.PrimaryContact.FirstName)
    </div>
    </div>
    <div class="editor-row">
        <div class="editor-label">
            @Html.LabelFor(model => model.ContactRelationship.SecondaryContactId)
        </div>
        <div class="editor-field">
            @Html.HiddenFor(model => model.ContactRelationship.SecondaryContactId)
            <div id="secondaryContactDetails">
                @if (Model.ContactRelationship.SecondaryContactId == default(int))
                {
                    <text>None Selected</text>
                }
                else
                {
                    <text>
                    @Html.DisplayFor(model => model.ContactRelationship.SecondaryContact.LastName),
                    @Html.DisplayFor(model => model.ContactRelationship.SecondaryContact.Title.Name)
                    @Html.DisplayFor(model => model.ContactRelationship.SecondaryContact.FirstName)
                    </text>
                }
            </div>
            <div id="showContactSelect">Select</div> 
            <div id="divContactSelect">
            </div>
        </div>
    </div>
    <div class="editor-row">
        <div class="editor-label">
            @Html.LabelFor(model => model.ContactRelationship.ContactRelationshipTypeId)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.ContactRelationship.ContactRelationshipTypeId, Model.ContactRelationshipTypeList)
            @Html.ValidationMessageFor(model => model.ContactRelationship.ContactRelationshipTypeId)
        </div>
    </div>